package homework.work3;

public class Teacher implements Cloneable{
    int age;
    String name;
    Student stu;

    //重写clone方法、深克隆
    @Override
    public Teacher clone() throws CloneNotSupportedException {
        Teacher cloneTeacher=(Teacher)super.clone();
        if(cloneTeacher.stu!=null){
            Student cloneStudent= cloneTeacher.stu.clone();
            cloneTeacher.stu=cloneStudent;
        }
        return cloneTeacher;
    }

    //构造器
    public Teacher() {
    }
    public Teacher(int age, String name) {
        this.age = age;
        this.name = name;
    }
    public Teacher(int age, String name, Student stu) {
        this.age = age;
        this.name = name;
        this.stu = stu;
    }
}
